<?php
/**
 * Created by.
 * User: littleU-569598569
 * Date: 2021/2/3 0003
 * Time: 22:41
 */

namespace app\api\service;

use app\api\model\Agency as AgencyModel;
use app\api\model\AgencyApply as AgencyApplyModel;

class Agency extends BaseService
{
    public function getAgencyByCondition($data)
    {
        $condition = [];
        $page = isset($data['page']) ? $data['page'] : $this->page;
        $limit = isset($data['limit']) ? $data['limit'] : $this->limit;
        $order = isset($data['order']) ? $data['order'] : $this->order;
        if (isset($data['status'])) {
            $condition['status'] = $data['status'];
        }
        if (isset($data['name'])) {
            $condition['name'] = ['like', '%' . $data['name'] . '%'];
        }
        if (isset($data['code'])) {
            $condition['code'] = $data['code'];
        }
        $result = (new AgencyModel())->where($condition)->page($page)->limit($limit)->order($order)->select();
        $count = (new AgencyModel())->where($condition)->count();

        return json([
            'code' => config('code.success'),
            'msg' => '请求成功',
            'data' => $result,
            'count' => $count
        ]);
    }
    public function getAgencyApplyByCondition($data)
    {
        $condition = [];
        $page = isset($data['page']) ? $data['page'] : $this->page;
        $limit = isset($data['limit']) ? $data['limit'] : $this->limit;
        $order = isset($data['order']) ? $data['order'] : $this->order;
        if (isset($data['status'])) {
            $condition['status'] = $data['status'];
        }
        if (isset($data['name'])) {
            $condition['name'] = ['like', '%' . $data['name'] . '%'];
        }
        if (isset($data['code'])) {
            $condition['code'] = $data['code'];
        }
        $result = (new AgencyApplyModel())->where($condition)->page($page)->limit($limit)->order($order)->select();
        $count = (new AgencyApplyModel())->where($condition)->count();

        return json([
            'code' => config('code.success'),
            'msg' => '请求成功',
            'data' => $result,
            'count' => $count
        ]);
    }
}